package com.cn.sys.main.aop;

import java.util.Date;

import org.joda.time.DateTime;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.TypeConverter;

import com.cn.sys.common.Constants;

public class ValueFormatTypeConverter implements TypeConverter {

	public boolean canConvert(TypeDescriptor sourceType,
			TypeDescriptor targetType) {
		return false;
	}

	public Object convertValue(Object value, TypeDescriptor sourceType,
			TypeDescriptor targetType) {
		if(value==null){
			return "";
		}
		Object returnValue = value;
		if(value instanceof Date){
			DateTime dateTime = new DateTime(value);
			returnValue = dateTime.toString(Constants.DATETIME_FORMAT);
		}else if(value instanceof Long || value instanceof Integer){
			returnValue = value.toString();
		}
		return returnValue;
	}

}